// if (process.env.NODE_ENV == "development") {
//     const VConsole = require("vconsole")
//     new VConsole();
// }
import Vue from "vue";
import FastClick from 'fastclick';
import { parseQuery } from "@/lib/util";
import Empty from "@/components/Empty/index.js";
import { Toast } from 'vant';
FastClick.attach(document.body);
/**注册图片预览全局指令 */
Vue.directive('fileView', {
    inserted: function(el, data) {
        let frameBOx = arguments[arguments.length];
        let iframe = null;
        el.addEventListener("click", async() => {
            /**检测是否存在文件**/
            if (!arguments[arguments.length]) {
                Toast.loading({
                    message: '加载中...',
                    forbidClick: true,
                    duration: 0
                });
                frameBOx = arguments[arguments.length] = document.createElement("div");
                iframe = document.createElement("iframe");
                iframe.src = encodeURI(data.value);
                iframe.style.cssText = "width:100%;height:100%;border:none;"
                frameBOx.style.cssText = "position:fixed;top:0;left:0;width:100%;height:100%;bottom:0;z-index:999;overflow:hidden;"
                frameBOx.appendChild(iframe);
                document.body.appendChild(frameBOx);
                iframe.onload = function() {
                    Toast.clear();
                }
                return
            }
            frameBOx.style.display = "block";
        });
        window.addEventListener("message", (e) => {

            let status = e.data.status;
            if (status) {
                frameBOx && (frameBOx.style.display = "none");
            }
        })
    },
    unbind: function() {
        console.log("unbind")
    }
})
try {
    var logInfo = `console.log('%c ${document.title} email:1418154909@qq.com(北京智明创兴) %c for Vue v${Vue.version} %c','background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px;  color: #fff','background:#41b883 ; padding: 1px; border-radius: 0 3px 3px 0;  color: #fff','background:transparent')`;
    eval(logInfo);
} catch (error) {
    console.log(error)
}
/**注册一个全局空数据组件 */
Vue.use(Empty);
window.onload = function() {
    try {


        let event = document.createEvent('Event');

        // // 定义事件名为'build'.
        event.initEvent('showPage', true, true);
        // // 触发对象可以是任何元素或其他事件目标

        document.addEventListener("visibilitychange", () => {
            if (document.hidden) { //处于当前页面

                window.dispatchEvent(event);


            }
        });
        window.addEventListener('pageshow', (e) => {
            if (e.persisted) {

                window.dispatchEvent(event);

            }
        })
    } catch (error) {
        console.log(error);
    }

}

window.sessionStorage.setItem("appName", document.title);

window.parseQuery = parseQuery();
try {
    !!window.parseQuery.userId && window.sessionStorage.setItem("ownid", window.parseQuery.userId);
    !!window.parseQuery.tenantId && window.sessionStorage.setItem("tenant_id", window.parseQuery.tenantId);
    !!window.parseQuery.staffNo && window.sessionStorage.setItem("staff_no", window.parseQuery.staffNo);
} catch (e) {
    throw "plugin.js 注入地址栏信息出错";
}

/**在plugins-》index.js里面生成的数据 */
if (process.env.NODE_ENV == "development") {
    window.sessionStorage.setItem("tenant_id", "735893790648176640");
    window.sessionStorage.setItem("staff_no", "D0025");
    window.sessionStorage.setItem("ownid", "800888883272224768");
} else {

    window.sessionStorage.getItem("tenantid") && window.sessionStorage.setItem("tenant_id", window.sessionStorage.getItem("tenantid"));
}

window.storeData = window.sessionStorage;

// console.log(window.sessionStorage, "缓存数据");